#Run script from localscript

1 messages · Page 1 of 1 (latest)

dull ibex
#

I have a localscript that makes three buttons for the player's UI and it runs a piece of code if the player selects a button. I want to run a different script inside a different part that damages a humanoid after the player selects one of the buttons. all I really need is the code for this. thank you for your help

rough timber
#

first i would have preset scripts in each part

#

then when the button is clicked

#

just enable the script

reef shuttleBOT
#

studio** You are now Level 3! **studio

dull ibex
rough timber
#

so do that to all scripts in this part for now

#

then

dense oxide
rough timber
#

then use script.Enabled = true to enable it

rough timber
#

but u can show them a better way

#

it works

dull ibex
rough timber
#

there are many ways

dense oxide
#

Are they both local scripts?

dull ibex
dense oxide
#

To communicate between local and server scripts you can use remote events

dull ibex
#

kk, thank you..!

#

@dense oxide I'm not understanding it

#

I can show you what I have so far in a little....

dense oxide
#

ok show

dull ibex
# dense oxide 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

dull ibex
#

Bumping! still need assistance :<

regal path
#

Oh I think I know why.

#

It doesn't work.

#

Yeah I know why

#

In this script