Code issues - Button does not work

hello! Could someone help me to fix my code please :frowning: when i press the button it does nothing, don’t work…

This is my code

LocalScript:

script.Parent.MouseButton1Click:Connect(function()

script.Parent.GizmoT:FireServer(game.ReplicatedStorage.Bomb_Animations.Bomb)

end)

ServerScript:

local event = script.Parent.Change

event.OnServerEvent:Connect(function(player,model)

local Char = model:Clone()

local Pos = player.Character:GetPrimaryPartCFrame()

player.Character:Destroy()

player.Character = Char

Char.Parent = workspace

Char:SetPrimaryPartCFrame(Pos)

end)

I don’t know what i’m doing wrong…

Here are some images of how my project is organized:

1

2

You may need to define the BombAnimation as a variable in your LocalScript, & make sure to add print statements as well in your ServerScript for debugging

--Local Script
local BombAnimation = game.ReplicatedStorage["Bomb_Animations"].Bomb
script.Parent.MouseButton1Click:Connect(function()
    script.Parent.GizmoT:FireServer(BombAnimation)
end)

Also make sure that whenever you see special symbols such as an underline like that, you need to specify it by using ["Random Thing Here"]

1 Like

You are firing the GizmoT event in the client, but only looking for the Change event in the server. I’m not sure which one you want to use but it seems you only need one.

3 Likes

Oh you are absolutely right! I just set it up and it works haha :slight_smile: thanks you a lot! :smiley:

2 Likes

It looks to me like you are firing one event from the localscript and listening for a different event on the server.

Change this (on the server script):

local event = script.Parent.Change

to this:

local event = script.Parent.GizmoT
1 Like

Thank you very much for that you helped me a lot! I’m still learning to code in this language, it’s been two weeks but I keep going, I always have to use the [“this”] or some times only?

Preferably just use it whenever you wanna exactly specify/define a certain thing, like say I have this:

local Part = game.Workspace.Part

But I put this instead:

local Part = game.Workspace.Part Moment

The second example won’t work because it’ll error as an “incomplete statement”, so to fix that you’d need to include those bracket specifiers:

local Part = game.Workspace["Part Moment"]

So this makes our Part specified! (Exactly case & space sensitive)

It’s completely optional if you have no special symbols or spaces in your variable you want to define, basically:

local Part = game.Workspace.Part

Is the same as

local Part = game.Workspace["Part"],

You’re just adding the unnecessary brackets :upside_down_face:
But if you come across a certain part that has special symbols or spaces, then that’s when you’d need to use those brackets correctly!

local Part = game.Workspace.Hi I'm A Part
N O G O O D

local Part = game.Workspace["Hi I'm A Part"]
Will work as it’s in the correct brackets!

2 Likes

I really like this type of code writing, I will start to use it when I am doing something, thank you very much for the tips! :smiley:

1 Like