#Run script from localscript
1 messages · Page 1 of 1 (latest)
well couple thing you can do
first i would have preset scripts in each part
then when the button is clicked
just enable the script
** You are now Level 3! **
I'm VERY new to scripting, so...idk how to do that ^^"
well if you right click a script you can disable it right?
so do that to all scripts in this part for now
then
This is extremely shit way of doing it
then use script.Enabled = true to enable it
well they said there not very good at coding
but u can show them a better way
it works
oh- so how else do I do it..?
there are many ways
Are they both local scripts?
one's a localscript since it's handling the UI. the other is a normal script
To communicate between local and server scripts you can use remote events
kk, thank you..!
@dense oxide I'm not understanding it
I can show you what I have so far in a little....
ok show
Script in the part that will hopefully be ran when the localscript runs:
local Workspace = game:GetService("Workspace")
-- Get reference to remote event instance
local remoteEvent = ReplicatedStorage:FindFirstChildOfClass("RemoteEvent")
local function DamageEnemy(player, damage)
print(player.Name .. " fired the RemoteEvent")
end
remoteEvent.OnServerEvent:Connect(onDamageEnemy)```
The second half of the code in the localscript that I'll want to call the function:
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Right then
selectionIndex = (selectionIndex % #options) + 1
updateSelection()
elseif input.KeyCode == Enum.KeyCode.Left then
selectionIndex = (selectionIndex - 2) % #options + 1
updateSelection()
elseif input.KeyCode == Enum.KeyCode.Z then
if options[selectionIndex] == "FIGHT" then
print("FIGHT option selected.")
(I WANT THE CALLING THE FUNCTION TO GO HERE!!)
remoteEvent:FireServer()
-- Add code to execute when FIGHT is selected
elseif options[selectionIndex] == "PRAY" then
print("PRAY option selected.")
-- Add code to execute when PRAY is selected
elseif options[selectionIndex] == "ITEM" then
print("ITEM option selected.")
-- Add code to execute when ITEM is selected
end
end
end)
updateSelection()
animateIcons()
in ReplicatedServerStorage I put a RemoteEvent called DamageEnemy
Bumping! still need assistance :<